//
//  BaseSignDetailsViewController.m
//  安好
//
//  Created by 马晓良 on 14-11-28.
//  Copyright (c) 2014年 lianchuangbrother. All rights reserved.
//

#import "BaseSignDetailsViewController.h"
#import "DetailsCell.h"
@interface BaseSignDetailsViewController ()<UITableViewDelegate,UITableViewDataSource>
/**
 *  基础体征tableView
 */
@property (strong, nonatomic) IBOutlet UITableView *baseSignDetailsTableView;
/**
 *  存放类型
 */
@property (nonatomic, strong) NSArray *typeArray;

@end

@implementation BaseSignDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.baseSignDetailsTableView.dataSource = self;
    self.baseSignDetailsTableView.delegate = self;
    self.baseSignDetailsTableView.backgroundColor = [ClassMethodsViewController colorWithHexString:BACK_BACKGROUNDCOLOR_16];
    [self setNaviBarAttribute];
    self.typeArray = @[self.detailsTypeStr,@"时间",@"来源",@"是否用户输入"];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
//    self.navigationController.navigationBar.translucent = NO;
}


- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
//    self.navigationController.navigationBar.translucent = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - 设置naviBar 并实现左右naviBar button方法 -
- (void)setNaviBarAttribute{
    /**
     *  设置左NaviBar和右naviBar
     */
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.frame = CGRectMake(0, 0, 23, 23);
    [leftButton setImage:[UIImage imageNamed:@"公用_返回"] forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(handleLeftButtonAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    
    self.navigationItem.title = self.detailsTypeStr;
}


/**
 *  返回主页面
 */
- (void)handleLeftButtonAction{
    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark - tableView的代理方法 -

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (kScreenWidth == 414) {
        return 54;
    }else{
        return 44;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DetailsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"detailsCell"];
    if (!cell) {
        if (kScreenWidth == 414) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"DetailsCell" owner:self options:nil] lastObject];
        }else{
            cell = [[[NSBundle mainBundle] loadNibNamed:@"DetailsCell" owner:self options:nil] firstObject];
        }
    }
    cell.detailsTypeLabel.text = self.typeArray[indexPath.row];
    if (indexPath.row == 0) {
        if ([self.detailsTypeStr isEqualToString:@"身高"]) {
            cell.detailsDataLabel.text = [NSString stringWithFormat:@"%@厘米",self.healthDataSource.height];
        }else if ([self.detailsTypeStr isEqualToString:@"体重"]){
            cell.detailsDataLabel.text = [NSString stringWithFormat:@"%@厘米",self.healthDataSource.weight];
        }else if ([self.detailsTypeStr isEqualToString:@"柔韧性"]){
            cell.detailsDataLabel.text = [NSString stringWithFormat:@"%@秒",self.healthDataSource.flexility];
        }else if ([self.detailsTypeStr isEqualToString:@"挥拳"]){
            cell.detailsDataLabel.text = [NSString stringWithFormat:@"%@次/10秒",self.healthDataSource.shake_fist];
        }else if ([self.detailsTypeStr isEqualToString:@"色觉"]){
            cell.detailsDataLabel.text = [NSString stringWithFormat:@"%@",self.healthDataSource.colorvision];
        }
    }else if(indexPath.row == 1){
        cell.detailsDataLabel.text = [self getDate:self.healthDataSource.dateline];
    }else if (indexPath.row == 2){
        cell.detailsDataLabel.text = [NSString stringWithFormat:@"%@",self.healthDataSource.source];
    }else{
        if ([self.healthDataSource.inputtype intValue] == 0) {
            cell.detailsDataLabel.text = @"否";
        }else{
            cell.detailsDataLabel.text = @"是";
        }
    }
    return cell;
}


#pragma mark - 时间戳转换成时间 -
- (NSString *)getDate:(NSString *)string{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
    [dateFormatter setDateFormat:@"yyyy年MM月dd日 HH:mm"];
    NSDate *theday = [NSDate dateWithTimeIntervalSince1970:[string doubleValue]];
    return [dateFormatter stringFromDate:theday];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
